// Tab component
use iced::{Element, widget::{button, row, text}};

/// Tab bar component
pub fn tab_bar<'a, Message>(
    tabs: &'a [(&'a str, bool)], // (label, is_active)
    on_tab_selected: impl Fn(usize) -> Message + 'a,
) -> Element<'a, Message>
where
    Message: Clone + 'a,
{
    let tab_buttons = tabs.iter().enumerate().map(|(index, (label, is_active))| {
        let mut btn = button(text(*label));

        if !is_active {
            btn = btn.on_press(on_tab_selected(index));
        }

        btn.into()
    }).collect::<Vec<Element<'a, Message>>>();

    row(tab_buttons).spacing(5).into()
}
